import request from '@/utils/request'

/**
 * 获取考试列表
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getExamList(params) {
  return request({
    url: '/api/exams/list',
    method: 'get',
    params
  })
}

/**
 * 获取近期考试列表
 * @param {Object} params - 查询参数，可以包含limit参数限制返回数量
 * @returns {Promise}
 */
export function getUpcomingExams(params) {
  return request({
    url: '/api/exams/upcoming',
    method: 'get',
    params
  })
}

/**
 * 获取考试详情
 * @param {String|Number} id - 考试ID
 * @returns {Promise}
 */
export function getExamDetail(id) {
  return request({
    url: `/api/exams/${id}`,
    method: 'get'
  })
}

/**
 * 获取考试统计数据
 * @returns {Promise}
 */
export function getExamStats() {
  return request({
    url: '/api/exams/stats',
    method: 'get'
  })
}

/**
 * 开始考试
 * @param {String|Number} id - 考试ID
 * @returns {Promise}
 */
export function startExam(id) {
  return request({
    url: `/api/exams/${id}/start`,
    method: 'post'
  })
}

/**
 * 提交考试答案
 * @param {String|Number} id - 考试ID
 * @param {Object} data - 答案数据
 * @returns {Promise}
 */
export function submitExamAnswers(id, data) {
  return request({
    url: `/api/exams/${id}/submit`,
    method: 'post',
    data
  })
}

/**
 * 获取考试结果
 * @param {String|Number} id - 考试ID
 * @returns {Promise}
 */
export function getExamResult(id) {
  return request({
    url: `/api/exams/results/${id}`,
    method: 'get'
  })
}

/**
 * 获取考试历史记录
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getExamHistory(params) {
  return request({
    url: '/api/exams/history',
    method: 'get',
    params
  })
}

/**
 * 获取错题集
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getWrongQuestions(params) {
  return request({
    url: '/api/exams/wrong-questions',
    method: 'get',
    params
  })
}

/**
 * 保存考试笔记
 * @param {String|Number} id - 考试ID
 * @param {Object} data - 笔记数据
 * @returns {Promise}
 */
export function saveExamNote(id, data) {
  return request({
    url: `/api/exams/${id}/notes`,
    method: 'post',
    data
  })
}

export default {
  getExamList,
  getUpcomingExams,
  getExamDetail,
  getExamStats,
  startExam,
  submitExamAnswers,
  getExamResult,
  getExamHistory,
  getWrongQuestions,
  saveExamNote
} 